package com.bjsxt.usercenter.user.service.impl;

import java.util.Map;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import com.alibaba.fastjson.JSONObject;
import com.bjsxt.usercenter.common.util.ConstatFinalUtil;
import com.bjsxt.usercenter.user.dao.IAAdminsDao;
import com.bjsxt.usercenter.user.pojo.AAdmins;
import com.bjsxt.usercenter.user.service.IUserService;

/**
 * 用户模块的service的实现类
 * @author lenovo
 *
 */
@Service("userService")
public class UserServiceImpl implements IUserService
{
	@Resource
	private IAAdminsDao adminsDao;

	/**
	 * 查询一条管理员记录
	 */
	@Override
	public AAdmins findOneAdminsService(Map<String, Object> condMap)
	{
		return this.adminsDao.findOne(condMap);
	}

	/**
	 * 保存一条管理员记录
	 */
	@Override
	public JSONObject saveOneAdminsService(AAdmins admins)
	{
		JSONObject resultJSON = new JSONObject();
		/*影响条数*/
		int res = this.adminsDao.save(admins);
		if(res > 0)
		{
			resultJSON.put("code", "0");
			resultJSON.put("info", ConstatFinalUtil.INFO_JSON.get("0"));
			
			/*存储data*/
			JSONObject dataJSON = new JSONObject();
			dataJSON.put("id", admins.getId() + "");
			dataJSON.put("effect", res + "");
			
			resultJSON.put("data", dataJSON);
		}else
		{
			resultJSON.put("code", "1");
			resultJSON.put("info", ConstatFinalUtil.INFO_JSON.get("1"));
		}
		return resultJSON;
	}

	/**
	 * 更新一条管理员记录
	 */
	@Override
	public JSONObject updateOneAdminsService(AAdmins admins)
	{
		JSONObject resultJSON = new JSONObject();
		/*影响条数*/
		int res = this.adminsDao.update(admins);
		if(res > 0)
		{
			resultJSON.put("code", "0");
			resultJSON.put("info", ConstatFinalUtil.INFO_JSON.get("0"));
			
			/*存储data*/
			JSONObject dataJSON = new JSONObject();
			dataJSON.put("id", admins.getId() + "");
			dataJSON.put("effect", res + "");
			
			resultJSON.put("data", dataJSON);
		}else
		{
			resultJSON.put("code", "2");
			resultJSON.put("info", ConstatFinalUtil.INFO_JSON.get("2"));
		}
		return resultJSON;
	}

	/**
	 * 删除一条管理员记录
	 */
	@Override
	public JSONObject deleteOneAdminsService(AAdmins admins)
	{
		JSONObject resultJSON = new JSONObject();
		/*影响条数*/
		int res = this.adminsDao.delete(admins);
		if(res > 0)
		{
			resultJSON.put("code", "0");
			resultJSON.put("info", ConstatFinalUtil.INFO_JSON.get("0"));
			
			/*存储data*/
			JSONObject dataJSON = new JSONObject();
			dataJSON.put("id", admins.getId() + "");
			dataJSON.put("effect", res + "");
			
			resultJSON.put("data", dataJSON);
		}else
		{
			resultJSON.put("code", "3");
			resultJSON.put("info", ConstatFinalUtil.INFO_JSON.get("3"));
		}
		return resultJSON;
	}

}
